/**
 * @file       Rect.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "typedefine.h"
#include "Rect.h"
#include "Point.h"

namespace NS_LCD_AFW
{

CRect::CRect() :
		m_nLeft(INVALID_POSITION), m_nTop(INVALID_POSITION), m_nWidth(
				INVALID_LENTGH), m_nHight(INVALID_LENTGH)
{
}

CRect::CRect(int left, int top, int width, int hight) :
		m_nLeft(left), m_nTop(top), m_nWidth(width), m_nHight(hight)
{
}

CRect::CRect(const CPoint & leftTop, const CPoint & rightBottom)
{
	this->setLeft(leftTop.getX());
	this->setTop(leftTop.getY());
	this->setWidth(rightBottom.getX() - leftTop.getX() + 1);
	this->setHight(rightBottom.getY() - leftTop.getY() + 1);
}

CRect::~CRect()
{
}

int CRect::getHight() const
{
	return m_nHight;
}

int CRect::getWidth() const
{
	return m_nWidth;
}

int CRect::getLeft() const
{
	return m_nLeft;
}

int CRect::getTop() const
{
	return m_nTop;
}

void CRect::setHight(int hight)
{
	m_nHight = hight;
}

void CRect::setWidth(int width)
{
	m_nWidth = width;
}

void CRect::setLeft(int left)
{
	m_nLeft = left;
}

void CRect::setTop(int top)
{
	m_nTop = top;
}

CPoint CRect::getLeftTop() const
{
	return CPoint(m_nLeft, m_nTop);
}

CPoint CRect::getRightBottom() const
{
	return CPoint(m_nLeft + m_nWidth - 1, m_nTop + m_nHight - 1);
}

CPoint CRect::getCenterPoint() const
{
	return CPoint(m_nLeft + m_nWidth / 2, m_nTop + m_nHight / 2);
}

bool CRect::isRectEmpty() const
{
	return (m_nWidth <= 0 || m_nHight <= 0);
}

bool CRect::isRectNull() const
{
	return (m_nLeft < 0 || m_nTop < 0) || isRectEmpty();
}

bool CRect::isPointInRect(const CPoint & pt) const
{
	return (pt.getX() >= m_nLeft && pt.getX() < m_nLeft + m_nWidth
			&& pt.getY() >= m_nTop && pt.getY() < m_nTop + m_nHight);
}

bool CRect::isEqualWith(const CRect & other) const
{
	return (this->m_nLeft == other.m_nLeft && this->m_nTop == other.m_nTop
			&& this->m_nWidth == other.m_nWidth
			&& this->m_nHight == other.m_nHight);
}

void CRect::offsetRect(int offsetX, int offsetY)
{
	m_nLeft += offsetX;
	m_nTop += offsetY;
}

bool CRect::isValidRect() const
{
	return (m_nWidth > 0 && m_nHight > 0);
}

bool CRect::operator ==(const CRect & other) const
{
	return isEqualWith(other);
}

bool CRect::operator !=(const CRect & other) const
{
	return !isEqualWith(other);
}

} /* namespace NS_LCD_AFW */
